package com.wuliupai.delivery.wuliupaidelivery.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;

/**
 * Descriptions：自定义ListView
 * 解决其作为ScrollView的子控件时，显示不全的问题
 * <p>
 * Author：ChenME
 * Date：11/18/2016
 * Email：ibelieve1210@163.com
 */
public class CustomListView extends ListView {
    public CustomListView(Context context) {
        super(context);
    }

    public CustomListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    /**
     * 只重写该方法，达到使ListView适应ScrollView的效果
     */
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        try {
            int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
            setMeasuredDimension(widthMeasureSpec, expandSpec);
            super.onMeasure(widthMeasureSpec, expandSpec);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}